const SpiderBaseClass = require('./SpiderBaseClass');

const listSize = 30;//列表页面有多少个主播信息
class SpiderCC extends SpiderBaseClass {

  /**
   * 获取第一页列表
   */
  static firstListPage() {
    return 0;
  }

  /**
   * 获取其它页码的列表页面
   * @param page
   */
  static async getListPage(page) {
    const res = await SpiderCC.get(SpiderCC.listPageUrl(page),
      {dataType: 'json'});

    const list = res.data.lives.map(room => {
      let gender = 0;
      if (room.gender === 'male')
        gender = 1;
      else if (room.gender === 'female')
        gender = 2;
      return {
        anchor: {
          room: room.ccid,
          name: room.nickname,
          gender,
          avatar: room.purl,
        },
        type: room.gamename,
        data: {
          num_watch: room.total_visitor,
          // num_live: room.liveMinute,// 不使用网易CC自带的直播时长
          num_live: 0,
          num_gift: 0,
          num_follower: room.follower_num,
        },
      };
    });
    return {
      nextPage: page + 1,
      hasNextPage: list.length >= listSize,
      list,
      page,
    };
  }

  /**
   * 获取直播间信息
   * @param room
   */
  static getRoom(room) {
  }

  /**
   * 生成列表页面的网址
   * @param page
   * @return string
   */
  static listPageUrl(page) {
    const start = listSize * page;
    return `http://cc.163.com/category/live/?format=json&start=${start}`;
  }

  /**
   * 生成直播间信息的网址
   * @param id
   * @return string
   */
  static roomUrl(id) {
  }

}

module.exports = SpiderCC;